<?php
// require dirname(__FILE__) . DIRECTORY_SEPARATOR . './../config.php';
require '/www/wwwroot/jdmwl.com/public/alipay.trade.wap.pay/aop/AopClient.php';
require '/www/wwwroot/jdmwl.com/public/alipay.trade.wap.pay/aop/AopCertClient.php';
require '/www/wwwroot/jdmwl.com/public/alipay.trade.wap.pay/aop/AopCertification.php';
require '/www/wwwroot/jdmwl.com/public/alipay.trade.wap.pay/aop/AlipayConfig.php';
require '/www/wwwroot/jdmwl.com/public/alipay.trade.wap.pay/aop/request/AlipayTradeWapPayRequest.php';

// 初始化SDK
$alipayClient = new AopClient(getAlipayConfig());
// 构造请求参数以调用接口
$request = new AlipayTradeWapPayRequest();
$model = array();

// 设置商户订单号
$model['out_trade_no'] = "70501111111S001111119";

// 设置订单总金额
$model['total_amount'] = "9.00";

// 设置订单标题
$model['subject'] = "大乐透";

// 设置产品码
$model['product_code'] = "QUICK_WAP_WAY";

// 设置针对用户授权接口
$model['auth_token'] = "appopenBb64d181d0146481ab6a762c00714cC27";

// 设置用户付款中途退出返回商户网站的地址
$model['quit_url'] = "http://www.taobao.com/product/113714.html";

// 设置订单包含的商品列表信息
$goodsDetail = array();
$goodsDetail0 = array();
$goodsDetail0['goods_name'] = "ipad";
$goodsDetail0['alipay_goods_id'] = "20010001";
$goodsDetail0['quantity'] = 1;
$goodsDetail0['price'] = "2000";
$goodsDetail0['goods_id'] = "apple-01";
$goodsDetail0['goods_category'] = "34543238";
$goodsDetail0['categories_tree'] = "124868003|126232002|126252004";
$goodsDetail0['body'] = "特价手机";
$goodsDetail0['show_url'] = "http://www.alipay.com/xxx.jpg";
$goodsDetail[] = $goodsDetail0;
$model['goods_detail'] = $goodsDetail;

// 设置订单绝对超时时间
$model['time_expire'] = "2016-12-31 10:05:00";

// 设置业务扩展参数
$extendParams = array();
$extendParams['sys_service_provider_id'] = "2088511833207846";
$extendParams['hb_fq_seller_percent'] = "100";
$extendParams['hb_fq_num'] = "3";
$extendParams['industry_reflux_info'] = "{\"scene_code\":\"metro_tradeorder\",\"channel\":\"xxxx\",\"scene_data\":{\"asset_name\":\"ALIPAY\"}}";
$extendParams['royalty_freeze'] = "true";
$extendParams['card_type'] = "S0JP0000";
$model['extend_params'] = $extendParams;

// 设置商户传入业务信息
$model['business_params'] = "{\"mc_create_trade_ip\":\"127.0.0.1\"}";

// 设置公用回传参数
$model['passback_params'] = "merchantBizType%3d3C%26merchantBizNo%3d2016010101111";

// 设置商户的原始订单号
$model['merchant_order_no'] = "20161008001";

// 设置外部指定买家
$extUserInfo = array();
$extUserInfo['cert_type'] = "IDENTITY_CARD";
$extUserInfo['cert_no'] = "362334768769238881";
$extUserInfo['name'] = "李明";
$extUserInfo['mobile'] = "16587658765";
$extUserInfo['fix_buyer'] = "F";
$extUserInfo['min_age'] = "18";
$extUserInfo['need_check_info'] = "F";
$extUserInfo['identity_hash'] = "27bfcd1dee4f22c8fe8a2374af9b660419d1361b1c207e9b41a754a113f38fcc";
$model['ext_user_info'] = $extUserInfo;

$request->setBizContent(json_encode($model, JSON_UNESCAPED_UNICODE));
// 如果是第三方代调用模式，请设置app_auth_token（应用授权令牌）
$pageRedirectionData = $alipayClient->pageExecute($request, "GET");
// 如果需要返回GET请求，请使用
// $pageRedirectionData = $alipayClient->pageExecute($request, "GET");
echo $pageRedirectionData;

function getAlipayConfig()
{
    $privateKey  = file_get_contents('/www/wwwroot/jdmwl.com/extend/zfbpay/cert/private_key.txt');
    $alipayPublicKey = file_get_contents('/www/wwwroot/jdmwl.com/extend/zfbpay/cert/alipay_public_key.txt');
    $alipayConfig = new AlipayConfig();
    $alipayConfig->setServerUrl('https://openapi.alipay.com/gateway.do');
    $alipayConfig->setAppId('2021004178657055');
    $alipayConfig->setPrivateKey($privateKey);
    $alipayConfig->setFormat('json');
    $alipayConfig->setAlipayPublicKey($alipayPublicKey);
    $alipayConfig->setCharset('UTF-8');
    $alipayConfig->setSignType('RSA2');
    return $alipayConfig;
}
